package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.shopping.converter.TestProductConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ITestProductServiceImpl implements ITestProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    TestProductConverter productConverter;

    @Override
    public TestProductDetailDto getProductDetail(Long productId) {

        // 访问数据库获取数据
        Item item = itemMapper.selectByPrimaryKey(productId);

        // 有一段复杂的业务逻辑，在任何一地方，有可能出现异常，抛出一个自定义异常


        // 对象类型转化
        TestProductDetailDto testProductDetailDto = productConverter.itemDoToDto(item);

        return testProductDetailDto;
    }
}
